package C053;

/**
 * ClassName: C03
 * Package: C053
 * Description:
 *
 * @Author BCXJ
 * @Create 2025/4/8 00:10
 * @Version 1.0
 * @Since 1.0
 */
public class C03 {
    public static void main(String[] args) {
        int[] arr = {5,3,4,4,7,3,6,11,8,5,11};
        int[] arr2 = {4,5,7,7,13};
        //int[] arr3 = {10,6,5,10,15};
        int[] arr3 = {7,14,4,14,13,2,6,13};
        //System.out.println(totalSteps(arr2));
        System.out.println(totalSteps(arr3));
    }

    static int MAXLEN = 100001;
    static int[][] s = new int[MAXLEN][2];
    static int size = 0;
    public static int totalSteps(int[] nums) {
        size = 0;
        int res = 0;
        for (int i = nums.length - 1, curTurns; i >= 0; i--) {
            curTurns = 0;
            while(size > 0 && nums[i] > s[size - 1][0]) {
                curTurns = Math.max(curTurns + 1, s[size - 1][1]);
                size --;
            }
            s[size][0] = nums[i];
            s[size++][1] = curTurns;
            res = Math.max(res, curTurns);
        }

        return res;
    }
}
